#include <iostream>
#include <string>

using namespace std;

class logger {
public:
    enum log_level {
        LeveLInfo = 0,
        LevelWarn, 
        LevelError
    };

    int current_level;

    void setLogLevel(int level) {
        current_level = level;
    }
    logger() : current_level(LeveLInfo) {}

    void log(log_level lvl, const string& msg) {
        // ANSI转义序列来设置颜色
        const char* color;
        switch (lvl) {
            case LevelError:
                color = "\033[31m"; // 红色
                break;
            case LevelWarn:
                color = "\033[33m"; // 黄色
                break;
            case LeveLInfo:
                color = "\033[32m"; // 绿色
                break;
            default:
                color = "\033[0m"; // 默认颜色
        }

        // 重置颜色的ANSI转义序列
        const string resetColor = "\033[0m";

        // 输出带有颜色的日志
        if (lvl >= current_level) {
            cout << color << getLevelString(lvl) << ": " << msg << resetColor << endl;
        }
    }

    // 辅助函数，用于获取日志级别的字符串表示
    string getLevelString(log_level lvl) {
        switch (lvl) {
            case LevelError:
                return "ERROR";
            case LevelWarn:
                return "WARNING";
            default:
                return "INFO";
        }
    }
    void logError(const string& msg) {
        log(LevelError, msg);
    }

    void logWarning(const string& msg) {
        log(LevelWarn, msg);
    }

    void logInfo(const string& msg) {
        log(LeveLInfo, msg);
    }
};

int main() {
    logger log;
    //log.setLogLevel(logger::info);
    log.logInfo("This is an info message.");
    log.logWarning("This is a warning message.");
    log.logError("This is an error message.");
    return 0;
}